#include "node.h"
#include<stdio.h>
#include<stdlib.h>
typedef struct _List{
    Node *head;
    Node *tail;
}List;
void print(List *pList);
void chick(List *plist);
void delete(List *plist);
void deleteall(List *plist);
void addlast(List* plist,int number);
void addfirstwh(List* plist,int number);
void addfirstwoh(List* plist,int number);
int main(int argc,char const *argv[]){
    List list;
    list.head = list.tail = (Node*)malloc(sizeof(Node));
    //list.head->next = list.tail;
    list.tail->next =list.head->next = NULL;
    int number;
    scanf("%d",&number);
    list.head->value = number;
    do{ 
        scanf("%d",&number);   
        if(number != -1){
         addlast(&list,number);
         }
    }while(number != -1);
    //链表的遍历
   print(&list);
   chick(&list);
delete(&list);
print(&list);
deleteall(&list);
print(&list);
    return 0;
}
void addlast(List* plist,int number){
        Node *p = (Node*)malloc(sizeof(Node)); 
                p->value = number;
                p->next = NULL;
                plist->tail->next = p ;
                plist->tail = p ;
}
void addfirstwh(List* plist,int number){
        Node *p = (Node*)malloc(sizeof(Node)); 
                p->value = number;
                p->next = NULL;
                p->next = plist->head->next;
                plist->head->next = p;
}              
void addfirstwoh(List* plist,int number){
    Node* p = (Node*)malloc(sizeof(Node));
    p->value = number;
    p->next = NULL;
    p->next = plist->head;
    plist->head = p;
}
void print(List *pList){
    Node *p;
   for(p = pList->head;p;p = p->next){
        printf("%d\t",p->value);
    } 
    printf("\n");
}
void chick(List *plist){
    int number;
    scanf("%d",&number);
Node* p;
int isFound = 0;
for(p = plist->head;p;p = p->next){
    if(p->value == number){
    printf("找到了\n");
    isFound = 1;
    break;
    }
}
if(!isFound){
    printf("没找到");
}

}
void delete(List *plist){
Node* q,*p;
int number;
printf("你想删除哪个数:");
scanf("%d",&number);
for(q = NULL,p = plist->head;p;q = p,p = p->next){
    if(p->value == number){
        if(q){
            q->next = p->next;
        }else{
            plist->head = p->next;
        }
        free(p);
        break;
        }
    }
}
void deleteall(List *plist){
Node* q,*p;
for(q = NULL,p = plist->head;p;q = p,p = p->next){
        if(q){
            q->next = p->next;
        }else{
            plist->head = p->next;
        }
        free(p);
    }
}